﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OrganizedIN.DAL;
using OrganizedIN.BAL;
using OrganizedIN.BussinessServices;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using OrganizedIN.BAL.Common;
using System.Data;

namespace OrganizedIN.UI.video
{
    public partial class view_album : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (Session["UserID"] != null)
                {
                    if (Request.QueryString["album_id"] != null && Request.QueryString["album_id"] != "")
                    {
                        string album_id = Request.QueryString["album_id"].Trim();
                        DataSet ds = new DataSet();
                        string uid = Convert.ToString(Session["UserID"]);
                        ds = Common.Get_Video_Album_Vids(uid, album_id);

                        // Getting Album Details
                        DataSet album_details = Common.Get_Video_Album_Details(uid, album_id);
                        DataRow album_details_data = album_details.Tables[0].Rows[0];

                        string genHtml = "<h3>" + album_details_data[1].ToString() + "</h3><small>Created On: " + album_details_data[2].ToString() + "</small><br/><br/>";
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            string imgFile = string.Empty;
                            genHtml += "<ul style='list-style:none;'>";
                            int counter = 1;
                            foreach (DataRow row in ds.Tables[0].Rows)
                            {
                                if (row[0].ToString().IndexOf("www.youtube-nocookie.com") == -1)
                                {
                                    imgFile = row[0].ToString();
                                    imgFile = imgFile.Substring(0, imgFile.Length - 3) + "jpg";
                                }
                                else
                                {
                                    imgFile = "../../images/youtube.jpg";

                                }
                                genHtml += "<li>";
                                genHtml += "<a id='" + counter + "' class='video_links' href='" + row[0].ToString() + "'><img style='float:left;margin-right:10px;' alt='" + row[1].ToString() + "' src='" + imgFile + "' width='100px' height='60px' /></a>";
                                genHtml += "<h4>" + row[1].ToString() + "</h4>";
                                genHtml += "<p>" + row[2].ToString() + "</p>";
                                genHtml += "<p><a class='facebox' href='../GroupShare.aspx?Video_ID=" + row[4].ToString() + "'><img src='../../images/ShareWithGroup.jpg'></a></p>";
                                genHtml += Common.createRatingImages(Convert.ToInt16(row[3]));

                                genHtml += "<div class='video_player_div' id='video_player_" + counter + "' style='display:none;'></div>";
                                genHtml += "<div style='clear:both;'></div>";
                                genHtml += "</li>";
                                counter++;
                            }
                            genHtml += "</ul>";
                            left_pane.InnerHtml = genHtml;
                        }
                        else
                        {
                            vs.InnerText = "No video(s) found in the album.";
                        }
                    }
                    else
                    {
                        Response.Redirect("mypvideos.aspx");
                    }
                }
            }
            catch (Exception ex)
            {
                vs.InnerText = ex.ToString();
            }
        }
    }
}